package com.info.search;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.jsoup.Jsoup;

public class Kebiao {

	public static void main(String args[]) throws MalformedURLException,
			IOException {
		String xqd = "1";
		String xnd = "2013-2014";
		String urlkebiao = "http://218.195.32.11/(lt0wzs55y42iw124ayvqeq55)/xskbcx.aspx?xh=1205500121&xm=%B6%CE%B4%BA%D1%E0&gnmkdm=N121603";
		String resp=post("http://218.195.32.11/(lt0wzs55y42iw124ayvqeq55)/Default2.aspx",
						"__VIEWSTATE=dDwtMjEzNzcwMzMxNTs7Pvtubc5lBpdxzJkAVrAeUsbvOB6m&TextBox1=1205500121&TextBox2=1205500121&RadioButtonList1=%D1%A7%C9%FA&Button1=");
//		String ok = Jsoup.parse(get(urlkebiao)).select("table").toString();
		String ok = get(urlkebiao);
		String f = Jsoup.parse(ok).select("input[name$=__EVENTTARGET").first()
				.attr("value");
		System.out.println(StreamUtils.Stream2String(new FileInputStream("D://xiazai//test.txt")));
		String s = (post("http://218.195.32.11/(lt0wzs55y42iw124ayvqeq55)/xskbcx.aspx?xh=1205500121&xm=%B6%CE%B4%BA%D1%E0&gnmkdm=N121603",
						"__EVENTTARGET=xnd&__EVENTARGUMENT=&__VIEWSTATE="+StreamUtils.Stream2String(new FileInputStream("D://xiazai//test.txt")) + "&xnd=" + xnd + "&xqd=" + xqd));
		System.out.println(s);
		String p=StreamUtils.Stream2String(new FileInputStream("D://xiazai//test.txt"))+"&xnd=2014-2015&xqd=2";
	
		s=(post("http://218.195.32.11/(lt0wzs55y42iw124ayvqeq55)/xskbcx.aspx?xh=1205500121&xm=%B6%CE%B4%BA%D1%E0&gnmkdm=N121603",p));
		System.out.println(Jsoup.parse(s).select("table#Table1").attr("border", "1"));
		//	System.out.println(Jsoup.parse(Http.post("http://218.195.32.11/(umfxau553le1srvzeoakwcvg)/xskbcx.aspx?xh=1205500121&xm=%B6%CE%B4%BA%D1%E0&gnmkdm=N121603",StreamUtils.Stream2String(new FileInputStream("G://Xiaomi//xx.txt")))).select("span.formbox"));
	}

	static String post(String url, String p) throws MalformedURLException,
			IOException {

		URLConnection conn = new URL(url).openConnection();
		String s;
		conn.setRequestProperty("Origin", "http://218.195.32.11");
		conn.setRequestProperty("Referer", url);
		conn.setRequestProperty("Upgrade-Insecure-Requests", "1");
		conn.setRequestProperty(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36");

		// conn.setRequestProperty(
		// "Referer",
		// "http://218.195.32.11/(icq1h545n1xvg545qtz4fwro)/xxjsjy.aspx?xh=1205500121&xm=%B6%CE%B4%BA%D1%E0&gnmkdm=N121611");
		conn.setDoInput(true);
		conn.setDoOutput(true);

		if (p != null)
			conn.getOutputStream().write(p.getBytes());
		BufferedReader br = new BufferedReader(new InputStreamReader(
				conn.getInputStream()));
		StringBuffer b = new StringBuffer();
		while ((s = br.readLine()) != null) {
			b.append(s);
		}

		return b.toString();

	}

	static String get(String url) throws MalformedURLException, IOException {

		HttpURLConnection conn = (HttpURLConnection) new URL(url)
				.openConnection();
		conn.setRequestProperty("Referer", url);
		conn.setRequestProperty("Upgrade-Insecure-Requests", "1");
		// conn.setRequestProperty("Referer",
		// "http://218.195.32.11/(yh0kxoaa40kpjamm4u0myp55)/xs_main.aspx?xh=1205500121");
		String s;
		System.out.println(conn.getResponseCode());
		BufferedReader br = new BufferedReader(new InputStreamReader(
				conn.getInputStream()));
		StringBuffer b = new StringBuffer();
		while ((s = br.readLine()) != null) {
			b.append(s);
		}

		return b.toString();

	}
}
